package com.wholeintech.protocol;

import android.util.Log;
import static com.wholeintech.utils.CommonUtil.bytesToHexString;

public class NCN5120 {	
	private final static String TAG = "NCN5120";
	KNXBase mKNXBase=new KNXBase();
	
    public NCN5120() {
    }

	public byte[] getCtrlPacket(int mainGroup, int middleGroup, int subGroup , int data ){
		byte[] temp;
		byte[] out;
		
		temp=mKNXBase.getCtrlPacket(mainGroup, middleGroup, subGroup, data);
		out=new byte[temp.length*2];
		
		Log.d(TAG, "Knx org data :" + bytesToHexString(temp, temp.length));	
		 
		for(int i=0; i<temp.length ; i++)
		{
			if(i== (temp.length-1) )
				out[2*i]=(byte)(0x40 | i);
			else
				out[2*i]=(byte)(0x80 | i);
			out[2*i+1]=temp[i];
		}		
		return out;
	}
	
	byte [] getBytes(byte [] data)
	{
		byte [] out =new byte[data.length*2] ;
		
		Log.d(TAG, "Knx org data :" + bytesToHexString(data, data.length));	
		
		for(int i=0; i<data.length ; i++)
		{
			if(i== (data.length-1) )
				out[2*i]=(byte)(0x40 | i);
			else
				out[2*i]=(byte)(0x80 | i);
			out[2*i+1]=data[i];
		}			
		return out;
	}
	
	public byte[]  groupWriteBool(int mainGroup, int middleGroup, int subGroup, int value) {
		
		return (getBytes(mKNXBase.groupWriteBool(0, mainGroup, middleGroup, subGroup, value)));
	}

	public byte[] groupWriteByte(int mainGroup, int middleGroup, int subGroup, int value)
	{
		return (getBytes(mKNXBase.groupWriteByte(0, mainGroup, middleGroup, subGroup, value)));
	}

	public byte[]  groupReadBoolReq(int mainGroup, int middleGroup, int subGroup, int value)
	{
		return (getBytes(mKNXBase.groupReadBoolReq(0, mainGroup, middleGroup, subGroup, value)));
	}

	public byte[]  groupReadByte(int mainGroup, int middleGroup, int subGroup)
	{
		return (getBytes(mKNXBase.groupReadByte(0, mainGroup, middleGroup, subGroup)));
	}	
	
	public byte[] groupWriteFloat(int mainGroup, int middleGroup, int subGroup, float value)
	{
		return (getBytes(mKNXBase.groupWriteFloat(0, mainGroup, middleGroup, subGroup, value)));
	}
}
